//////////////////////////////////////////////////////////////////////
////                                                              ////
////  uart_rfifo.v (Modified from uart_fifo.v)                    ////
////                                                              ////
////                                                              ////
////  This file is part of the "UART 16550 compatible" project    ////
////  http://www.opencores.org/cores/uart16550/                   ////
////                                                              ////
////  Documentation related to this project:                      ////
////  - http://www.opencores.org/cores/uart16550/                 ////
////                                                              ////
////  Projects compatibility:                                     ////
////  - WISHBONE                                                  ////
////  RS232 Protocol                                              ////
////  16550D uart (mostly supported)                              ////
////                                                              ////
////  Overview (main Features):                                   ////
////  UART core receiver FIFO                                     ////
////                                                              ////
////  To Do:                                                      ////
////  Nothing.                                                    ////
////                                                              ////
////  Author(s):                                                  ////
////      - gorban@opencores.org                                  ////
////      - Jacob Gorban                                          ////
////      - Igor Mohor (igorm@opencores.org)                      ////
////                                                              ////
////  Created:        2001/05/12                                  ////
////  Last Updated:   2002/07/22                                  ////
////                  (See log for the revision history)          ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
////                                                              ////
//// Copyright (C) 2000, 2001 Authors                             ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//
// CVS Revision History
//
// $Log: not supported by cvs2svn $
// Revision 1.3  2003/06/11 16:37:47  gorban
// This fixes errors in some cases when data is being read and put to the FIFO at the same time. Patch is submitted by Scott Furman. Update is very recommended.
//
// Revision 1.2  2002/07/29 21:16:18  gorban
// The uart_defines.v file is included again in sources.
//
// Revision 1.1  2002/07/22 23:02:23  gorban
// Bug Fixes:
//  * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
//   Problem reported by Kenny.Tung.
//  * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
//
// Improvements:
//  * Made FIFO's as general inferrable memory where possible.
//  So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
//  This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
//
//  * Added optional baudrate output (baud_o).
//  This is identical to BAUDOUT* signal on 16550 chip.
//  It outputs 16xbit_clock_rate - the divided clock.
//  It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
//
// Revision 1.16  2001/12/20 13:25:46  mohor
// rx push changed to be only one cycle wide.
//
// Revision 1.15  2001/12/18 09:01:07  mohor
// Bug that was entered in the last update fixed (rx state machine).
//
// Revision 1.14  2001/12/17 14:46:48  mohor
// overrun signal was moved to separate block because many sequential lsr
// reads were preventing data from being written to rx fifo.
// underrun signal was not used and was removed from the project.
//
// Revision 1.13  2001/11/26 21:38:54  gorban
// Lots of fixes:
// Break condition wasn't handled correctly at all.
// LSR bits could lose their values.
// LSR value after reset was wrong.
// Timing of THRE interrupt signal corrected.
// LSR bit 0 timing corrected.
//
// Revision 1.12  2001/11/08 14:54:23  mohor
// Comments in Slovene language deleted, few small fixes for better work of
// old tools. IRQs need to be fix.
//
// Revision 1.11  2001/11/07 17:51:52  gorban
// Heavily rewritten interrupt and LSR subsystems.
// Many bugs hopefully squashed.
//
// Revision 1.10  2001/10/20 09:58:40  gorban
// Small synopsis fixes
//
// Revision 1.9  2001/08/24 21:01:12  mohor
// Things connected to parity changed.
// Clock devider changed.
//
// Revision 1.8  2001/08/24 08:48:10  mohor
// FIFO was not cleared after the data was read bug fixed.
//
// Revision 1.7  2001/08/23 16:05:05  mohor
// Stop bit bug fixed.
// Parity bug fixed.
// WISHBONE read cycle bug fixed,
// OE indicator (Overrun Error) bug fixed.
// PE indicator (Parity Error) bug fixed.
// Register read bug fixed.
//
// Revision 1.3  2001/05/31 20:08:01  gorban
// FIFO changes and other corrections.
//
// Revision 1.3  2001/05/27 17:37:48  gorban
// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.
//
// Revision 1.2  2001/05/17 18:34:18  gorban
// First 'stable' release. Should be sythesizable now. Also added new header.
//
// Revision 1.0  2001-05-17 21:27:12+02  jacob
// Initial revision
//
//

// synopsys translate_off
`include "timescale.v"
// synopsys translate_on

`include "uart_defines.v"

module uart_rfifo (
	clk, 
	rst,
	data_in,
	data_out,
// Control signals
	push, // push strobe, active high
	pop,   // pop strobe, active high
// status signals
	overrun,
	count,
	error_bit,
	fifo_reset,
	reset_status
	);


// FIFO parameters
parameter fifo_width = `UART_FIFO_WIDTH;
parameter fifo_depth = `UART_FIFO_DEPTH;
parameter fifo_pointer_w = `UART_FIFO_POINTER_W;
parameter fifo_counter_w = `UART_FIFO_COUNTER_W;

input				clk;
input				rst;
input				push;
input				pop;
input	[fifo_width-1:0]	data_in;
input				fifo_reset;
input       reset_status;

output	[fifo_width-1:0]	data_out;
output				overrun;
output	[fifo_counter_w-1:0]	count;
output				error_bit;

wire	[fifo_width-1:0]	data_out;
wire [7:0] data8_out;
// flags FIFO
reg	[2:0]	fifo[fifo_depth-1:0];

// FIFO pointers
reg	[fifo_pointer_w-1:0]	top;
reg	[fifo_pointer_w-1:0]	bottom;

reg	[fifo_counter_w-1:0]	count;
reg				overrun;

wire [fifo_pointer_w-1:0] top_plus_1 = top + 1'b1;

raminfr #(fifo_pointer_w,8,fifo_depth) rfifo  
        (.clk(clk), 
			.we(push), 
			.a(top), 
			.dpra(bottom), 
			.di(data_in[fifo_width-1:fifo_width-8]), 
			.dpo(data8_out)
		); 

always @(posedge clk or posedge rst) // synchronous FIFO
begin
	if (rst)
	begin
		top		<= #1 0;
		bottom		<= #1 1'b0;
		count		<= #1 0;
		fifo[0] <= #1 0;
		fifo[1] <= #1 0;
		fifo[2] <= #1 0;
		fifo[3] <= #1 0;
		fifo[4] <= #1 0;
		fifo[5] <= #1 0;
		fifo[6] <= #1 0;
		fifo[7] <= #1 0;
		fifo[8] <= #1 0;
		fifo[9] <= #1 0;
		fifo[10] <= #1 0;
		fifo[11] <= #1 0;
		fifo[12] <= #1 0;
		fifo[13] <= #1 0;
		fifo[14] <= #1 0;
		fifo[15] <= #1 0;
		fifo[16] <= #1 0;
		fifo[17] <= #1 0;
		fifo[18] <= #1 0;
		fifo[19] <= #1 0;
		fifo[20] <= #1 0;
		fifo[21] <= #1 0;
		fifo[22] <= #1 0;
		fifo[23] <= #1 0;
		fifo[24] <= #1 0;
		fifo[25] <= #1 0;
		fifo[26] <= #1 0;
		fifo[27] <= #1 0;
		fifo[28] <= #1 0;
		fifo[29] <= #1 0;
		fifo[30] <= #1 0;
		fifo[31] <= #1 0;
		fifo[32] <= #1 0;
		fifo[33] <= #1 0;
		fifo[34] <= #1 0;
		fifo[35] <= #1 0;
		fifo[36] <= #1 0;
		fifo[37] <= #1 0;
		fifo[38] <= #1 0;
		fifo[39] <= #1 0;
		fifo[40] <= #1 0;
		fifo[41] <= #1 0;
		fifo[42] <= #1 0;
		fifo[43] <= #1 0;
		fifo[44] <= #1 0;
		fifo[45] <= #1 0;
		fifo[46] <= #1 0;
		fifo[47] <= #1 0;
		fifo[48] <= #1 0;
		fifo[49] <= #1 0;
		fifo[50] <= #1 0;
		fifo[51] <= #1 0;
		fifo[52] <= #1 0;
		fifo[53] <= #1 0;
		fifo[54] <= #1 0;
		fifo[55] <= #1 0;
		fifo[56] <= #1 0;
		fifo[57] <= #1 0;
		fifo[58] <= #1 0;
		fifo[59] <= #1 0;
		fifo[60] <= #1 0;
		fifo[61] <= #1 0;
		fifo[62] <= #1 0;
		fifo[63] <= #1 0;
		fifo[64] <= #1 0;
		fifo[65] <= #1 0;
		fifo[66] <= #1 0;
		fifo[67] <= #1 0;
		fifo[68] <= #1 0;
		fifo[69] <= #1 0;
		fifo[70] <= #1 0;
		fifo[71] <= #1 0;
		fifo[72] <= #1 0;
		fifo[73] <= #1 0;
		fifo[74] <= #1 0;
		fifo[75] <= #1 0;
		fifo[76] <= #1 0;
		fifo[77] <= #1 0;
		fifo[78] <= #1 0;
		fifo[79] <= #1 0;
		fifo[80] <= #1 0;
		fifo[81] <= #1 0;
		fifo[82] <= #1 0;
		fifo[83] <= #1 0;
		fifo[84] <= #1 0;
		fifo[85] <= #1 0;
		fifo[86] <= #1 0;
		fifo[87] <= #1 0;
		fifo[88] <= #1 0;
		fifo[89] <= #1 0;
		fifo[90] <= #1 0;
		fifo[91] <= #1 0;
		fifo[92] <= #1 0;
		fifo[93] <= #1 0;
		fifo[94] <= #1 0;
		fifo[95] <= #1 0;
		fifo[96] <= #1 0;
		fifo[97] <= #1 0;
		fifo[98] <= #1 0;
		fifo[99] <= #1 0;
		fifo[100] <= #1 0;
		fifo[101] <= #1 0;
		fifo[102] <= #1 0;
		fifo[103] <= #1 0;
		fifo[104] <= #1 0;
		fifo[105] <= #1 0;
		fifo[106] <= #1 0;
		fifo[107] <= #1 0;
		fifo[108] <= #1 0;
		fifo[109] <= #1 0;
		fifo[110] <= #1 0;
		fifo[111] <= #1 0;
		fifo[112] <= #1 0;
		fifo[113] <= #1 0;
		fifo[114] <= #1 0;
		fifo[115] <= #1 0;
		fifo[116] <= #1 0;
		fifo[117] <= #1 0;
		fifo[118] <= #1 0;
		fifo[119] <= #1 0;
		fifo[120] <= #1 0;
		fifo[121] <= #1 0;
		fifo[122] <= #1 0;
		fifo[123] <= #1 0;
		fifo[124] <= #1 0;
		fifo[125] <= #1 0;
		fifo[126] <= #1 0;
		fifo[127] <= #1 0;
		fifo[128] <= #1 0;
		fifo[129] <= #1 0;
		fifo[130] <= #1 0;
		fifo[131] <= #1 0;
		fifo[132] <= #1 0;
		fifo[133] <= #1 0;
		fifo[134] <= #1 0;
		fifo[135] <= #1 0;
		fifo[136] <= #1 0;
		fifo[137] <= #1 0;
		fifo[138] <= #1 0;
		fifo[139] <= #1 0;
		fifo[140] <= #1 0;
		fifo[141] <= #1 0;
		fifo[142] <= #1 0;
		fifo[143] <= #1 0;
		fifo[144] <= #1 0;
		fifo[145] <= #1 0;
		fifo[146] <= #1 0;
		fifo[147] <= #1 0;
		fifo[148] <= #1 0;
		fifo[149] <= #1 0;
		fifo[150] <= #1 0;
		fifo[151] <= #1 0;
		fifo[152] <= #1 0;
		fifo[153] <= #1 0;
		fifo[154] <= #1 0;
		fifo[155] <= #1 0;
		fifo[156] <= #1 0;
		fifo[157] <= #1 0;
		fifo[158] <= #1 0;
		fifo[159] <= #1 0;
		fifo[160] <= #1 0;
		fifo[161] <= #1 0;
		fifo[162] <= #1 0;
		fifo[163] <= #1 0;
		fifo[164] <= #1 0;
		fifo[165] <= #1 0;
		fifo[166] <= #1 0;
		fifo[167] <= #1 0;
		fifo[168] <= #1 0;
		fifo[169] <= #1 0;
		fifo[170] <= #1 0;
		fifo[171] <= #1 0;
		fifo[172] <= #1 0;
		fifo[173] <= #1 0;
		fifo[174] <= #1 0;
		fifo[175] <= #1 0;
		fifo[176] <= #1 0;
		fifo[177] <= #1 0;
		fifo[178] <= #1 0;
		fifo[179] <= #1 0;
		fifo[180] <= #1 0;
		fifo[181] <= #1 0;
		fifo[182] <= #1 0;
		fifo[183] <= #1 0;
		fifo[184] <= #1 0;
		fifo[185] <= #1 0;
		fifo[186] <= #1 0;
		fifo[187] <= #1 0;
		fifo[188] <= #1 0;
		fifo[189] <= #1 0;
		fifo[190] <= #1 0;
		fifo[191] <= #1 0;
		fifo[192] <= #1 0;
		fifo[193] <= #1 0;
		fifo[194] <= #1 0;
		fifo[195] <= #1 0;
		fifo[196] <= #1 0;
		fifo[197] <= #1 0;
		fifo[198] <= #1 0;
		fifo[199] <= #1 0;
		fifo[200] <= #1 0;
		fifo[201] <= #1 0;
		fifo[202] <= #1 0;
		fifo[203] <= #1 0;
		fifo[204] <= #1 0;
		fifo[205] <= #1 0;
		fifo[206] <= #1 0;
		fifo[207] <= #1 0;
		fifo[208] <= #1 0;
		fifo[209] <= #1 0;
		fifo[210] <= #1 0;
		fifo[211] <= #1 0;
		fifo[212] <= #1 0;
		fifo[213] <= #1 0;
		fifo[214] <= #1 0;
		fifo[215] <= #1 0;
		fifo[216] <= #1 0;
		fifo[217] <= #1 0;
		fifo[218] <= #1 0;
		fifo[219] <= #1 0;
		fifo[220] <= #1 0;
		fifo[221] <= #1 0;
		fifo[222] <= #1 0;
		fifo[223] <= #1 0;
		fifo[224] <= #1 0;
		fifo[225] <= #1 0;
		fifo[226] <= #1 0;
		fifo[227] <= #1 0;
		fifo[228] <= #1 0;
		fifo[229] <= #1 0;
		fifo[230] <= #1 0;
		fifo[231] <= #1 0;
		fifo[232] <= #1 0;
		fifo[233] <= #1 0;
		fifo[234] <= #1 0;
		fifo[235] <= #1 0;
		fifo[236] <= #1 0;
		fifo[237] <= #1 0;
		fifo[238] <= #1 0;
		fifo[239] <= #1 0;
		fifo[240] <= #1 0;
		fifo[241] <= #1 0;
		fifo[242] <= #1 0;
		fifo[243] <= #1 0;
		fifo[244] <= #1 0;
		fifo[245] <= #1 0;
		fifo[246] <= #1 0;
		fifo[247] <= #1 0;
		fifo[248] <= #1 0;
		fifo[249] <= #1 0;
		fifo[250] <= #1 0;
		fifo[251] <= #1 0;
		fifo[252] <= #1 0;
		fifo[253] <= #1 0;
		fifo[254] <= #1 0;
		fifo[255] <= #1 0;
	end
	else
	if (fifo_reset) begin
		top		<= #1 0;
		bottom		<= #1 1'b0;
		count		<= #1 0;
		fifo[0] <= #1 0;
		fifo[1] <= #1 0;
		fifo[2] <= #1 0;
		fifo[3] <= #1 0;
		fifo[4] <= #1 0;
		fifo[5] <= #1 0;
		fifo[6] <= #1 0;
		fifo[7] <= #1 0;
		fifo[8] <= #1 0;
		fifo[9] <= #1 0;
		fifo[10] <= #1 0;
		fifo[11] <= #1 0;
		fifo[12] <= #1 0;
		fifo[13] <= #1 0;
		fifo[14] <= #1 0;
		fifo[15] <= #1 0;
		fifo[16] <= #1 0;
		fifo[17] <= #1 0;
		fifo[18] <= #1 0;
		fifo[19] <= #1 0;
		fifo[20] <= #1 0;
		fifo[21] <= #1 0;
		fifo[22] <= #1 0;
		fifo[23] <= #1 0;
		fifo[24] <= #1 0;
		fifo[25] <= #1 0;
		fifo[26] <= #1 0;
		fifo[27] <= #1 0;
		fifo[28] <= #1 0;
		fifo[29] <= #1 0;
		fifo[30] <= #1 0;
		fifo[31] <= #1 0;
		fifo[32] <= #1 0;
		fifo[33] <= #1 0;
		fifo[34] <= #1 0;
		fifo[35] <= #1 0;
		fifo[36] <= #1 0;
		fifo[37] <= #1 0;
		fifo[38] <= #1 0;
		fifo[39] <= #1 0;
		fifo[40] <= #1 0;
		fifo[41] <= #1 0;
		fifo[42] <= #1 0;
		fifo[43] <= #1 0;
		fifo[44] <= #1 0;
		fifo[45] <= #1 0;
		fifo[46] <= #1 0;
		fifo[47] <= #1 0;
		fifo[48] <= #1 0;
		fifo[49] <= #1 0;
		fifo[50] <= #1 0;
		fifo[51] <= #1 0;
		fifo[52] <= #1 0;
		fifo[53] <= #1 0;
		fifo[54] <= #1 0;
		fifo[55] <= #1 0;
		fifo[56] <= #1 0;
		fifo[57] <= #1 0;
		fifo[58] <= #1 0;
		fifo[59] <= #1 0;
		fifo[60] <= #1 0;
		fifo[61] <= #1 0;
		fifo[62] <= #1 0;
		fifo[63] <= #1 0;
		fifo[64] <= #1 0;
		fifo[65] <= #1 0;
		fifo[66] <= #1 0;
		fifo[67] <= #1 0;
		fifo[68] <= #1 0;
		fifo[69] <= #1 0;
		fifo[70] <= #1 0;
		fifo[71] <= #1 0;
		fifo[72] <= #1 0;
		fifo[73] <= #1 0;
		fifo[74] <= #1 0;
		fifo[75] <= #1 0;
		fifo[76] <= #1 0;
		fifo[77] <= #1 0;
		fifo[78] <= #1 0;
		fifo[79] <= #1 0;
		fifo[80] <= #1 0;
		fifo[81] <= #1 0;
		fifo[82] <= #1 0;
		fifo[83] <= #1 0;
		fifo[84] <= #1 0;
		fifo[85] <= #1 0;
		fifo[86] <= #1 0;
		fifo[87] <= #1 0;
		fifo[88] <= #1 0;
		fifo[89] <= #1 0;
		fifo[90] <= #1 0;
		fifo[91] <= #1 0;
		fifo[92] <= #1 0;
		fifo[93] <= #1 0;
		fifo[94] <= #1 0;
		fifo[95] <= #1 0;
		fifo[96] <= #1 0;
		fifo[97] <= #1 0;
		fifo[98] <= #1 0;
		fifo[99] <= #1 0;
		fifo[100] <= #1 0;
		fifo[101] <= #1 0;
		fifo[102] <= #1 0;
		fifo[103] <= #1 0;
		fifo[104] <= #1 0;
		fifo[105] <= #1 0;
		fifo[106] <= #1 0;
		fifo[107] <= #1 0;
		fifo[108] <= #1 0;
		fifo[109] <= #1 0;
		fifo[110] <= #1 0;
		fifo[111] <= #1 0;
		fifo[112] <= #1 0;
		fifo[113] <= #1 0;
		fifo[114] <= #1 0;
		fifo[115] <= #1 0;
		fifo[116] <= #1 0;
		fifo[117] <= #1 0;
		fifo[118] <= #1 0;
		fifo[119] <= #1 0;
		fifo[120] <= #1 0;
		fifo[121] <= #1 0;
		fifo[122] <= #1 0;
		fifo[123] <= #1 0;
		fifo[124] <= #1 0;
		fifo[125] <= #1 0;
		fifo[126] <= #1 0;
		fifo[127] <= #1 0;
		fifo[128] <= #1 0;
		fifo[129] <= #1 0;
		fifo[130] <= #1 0;
		fifo[131] <= #1 0;
		fifo[132] <= #1 0;
		fifo[133] <= #1 0;
		fifo[134] <= #1 0;
		fifo[135] <= #1 0;
		fifo[136] <= #1 0;
		fifo[137] <= #1 0;
		fifo[138] <= #1 0;
		fifo[139] <= #1 0;
		fifo[140] <= #1 0;
		fifo[141] <= #1 0;
		fifo[142] <= #1 0;
		fifo[143] <= #1 0;
		fifo[144] <= #1 0;
		fifo[145] <= #1 0;
		fifo[146] <= #1 0;
		fifo[147] <= #1 0;
		fifo[148] <= #1 0;
		fifo[149] <= #1 0;
		fifo[150] <= #1 0;
		fifo[151] <= #1 0;
		fifo[152] <= #1 0;
		fifo[153] <= #1 0;
		fifo[154] <= #1 0;
		fifo[155] <= #1 0;
		fifo[156] <= #1 0;
		fifo[157] <= #1 0;
		fifo[158] <= #1 0;
		fifo[159] <= #1 0;
		fifo[160] <= #1 0;
		fifo[161] <= #1 0;
		fifo[162] <= #1 0;
		fifo[163] <= #1 0;
		fifo[164] <= #1 0;
		fifo[165] <= #1 0;
		fifo[166] <= #1 0;
		fifo[167] <= #1 0;
		fifo[168] <= #1 0;
		fifo[169] <= #1 0;
		fifo[170] <= #1 0;
		fifo[171] <= #1 0;
		fifo[172] <= #1 0;
		fifo[173] <= #1 0;
		fifo[174] <= #1 0;
		fifo[175] <= #1 0;
		fifo[176] <= #1 0;
		fifo[177] <= #1 0;
		fifo[178] <= #1 0;
		fifo[179] <= #1 0;
		fifo[180] <= #1 0;
		fifo[181] <= #1 0;
		fifo[182] <= #1 0;
		fifo[183] <= #1 0;
		fifo[184] <= #1 0;
		fifo[185] <= #1 0;
		fifo[186] <= #1 0;
		fifo[187] <= #1 0;
		fifo[188] <= #1 0;
		fifo[189] <= #1 0;
		fifo[190] <= #1 0;
		fifo[191] <= #1 0;
		fifo[192] <= #1 0;
		fifo[193] <= #1 0;
		fifo[194] <= #1 0;
		fifo[195] <= #1 0;
		fifo[196] <= #1 0;
		fifo[197] <= #1 0;
		fifo[198] <= #1 0;
		fifo[199] <= #1 0;
		fifo[200] <= #1 0;
		fifo[201] <= #1 0;
		fifo[202] <= #1 0;
		fifo[203] <= #1 0;
		fifo[204] <= #1 0;
		fifo[205] <= #1 0;
		fifo[206] <= #1 0;
		fifo[207] <= #1 0;
		fifo[208] <= #1 0;
		fifo[209] <= #1 0;
		fifo[210] <= #1 0;
		fifo[211] <= #1 0;
		fifo[212] <= #1 0;
		fifo[213] <= #1 0;
		fifo[214] <= #1 0;
		fifo[215] <= #1 0;
		fifo[216] <= #1 0;
		fifo[217] <= #1 0;
		fifo[218] <= #1 0;
		fifo[219] <= #1 0;
		fifo[220] <= #1 0;
		fifo[221] <= #1 0;
		fifo[222] <= #1 0;
		fifo[223] <= #1 0;
		fifo[224] <= #1 0;
		fifo[225] <= #1 0;
		fifo[226] <= #1 0;
		fifo[227] <= #1 0;
		fifo[228] <= #1 0;
		fifo[229] <= #1 0;
		fifo[230] <= #1 0;
		fifo[231] <= #1 0;
		fifo[232] <= #1 0;
		fifo[233] <= #1 0;
		fifo[234] <= #1 0;
		fifo[235] <= #1 0;
		fifo[236] <= #1 0;
		fifo[237] <= #1 0;
		fifo[238] <= #1 0;
		fifo[239] <= #1 0;
		fifo[240] <= #1 0;
		fifo[241] <= #1 0;
		fifo[242] <= #1 0;
		fifo[243] <= #1 0;
		fifo[244] <= #1 0;
		fifo[245] <= #1 0;
		fifo[246] <= #1 0;
		fifo[247] <= #1 0;
		fifo[248] <= #1 0;
		fifo[249] <= #1 0;
		fifo[250] <= #1 0;
		fifo[251] <= #1 0;
		fifo[252] <= #1 0;
		fifo[253] <= #1 0;
		fifo[254] <= #1 0;
		fifo[255] <= #1 0;
	end
  else
	begin
		case ({push, pop})
		2'b10 : if (count<fifo_depth)  // overrun condition
			begin
				top       <= #1 top_plus_1;
				fifo[top] <= #1 data_in[2:0];
				count     <= #1 count + 1'b1;
			end
		2'b01 : if(count>0)
			begin
        		fifo[bottom] <= #1 0;
				bottom   <= #1 bottom + 1'b1;
				count	 <= #1 count - 1'b1;
			end
		2'b11 : begin
				bottom   <= #1 bottom + 1'b1;
				top       <= #1 top_plus_1;
				fifo[top] <= #1 data_in[2:0];
		        end
    default: ;
		endcase
	end
end   // always

always @(posedge clk or posedge rst) // synchronous FIFO
begin
  if (rst)
    overrun   <= #1 1'b0;
  else
  if(fifo_reset | reset_status) 
    overrun   <= #1 1'b0;
  else
  if(push & ~pop & (count==fifo_depth))
    overrun   <= #1 1'b1;
end   // always


// please note though that data_out is only valid one clock after pop signal
assign data_out = {data8_out,fifo[bottom]};

// Additional logic for detection of error conditions (parity and framing) inside the FIFO
// for the Line Status Register bit 7

wire	[2:0]	word0 = fifo[0];
wire	[2:0]	word1 = fifo[1];
wire	[2:0]	word2 = fifo[2];
wire	[2:0]	word3 = fifo[3];
wire	[2:0]	word4 = fifo[4];
wire	[2:0]	word5 = fifo[5];
wire	[2:0]	word6 = fifo[6];
wire	[2:0]	word7 = fifo[7];

wire	[2:0]	word8 = fifo[8];
wire	[2:0]	word9 = fifo[9];
wire	[2:0]	word10 = fifo[10];
wire	[2:0]	word11 = fifo[11];
wire	[2:0]	word12 = fifo[12];
wire	[2:0]	word13 = fifo[13];
wire	[2:0]	word14 = fifo[14];
wire	[2:0]	word15 = fifo[15];

wire	[2:0]	word16 = fifo[16];
wire	[2:0]	word17 = fifo[17];
wire	[2:0]	word18 = fifo[18];
wire	[2:0]	word19 = fifo[19];
wire	[2:0]	word20 = fifo[20];
wire	[2:0]	word21 = fifo[21];
wire	[2:0]	word22 = fifo[22];
wire	[2:0]	word23 = fifo[23];

wire	[2:0]	word24 = fifo[24];
wire	[2:0]	word25 = fifo[25];
wire	[2:0]	word26 = fifo[26];
wire	[2:0]	word27 = fifo[27];
wire	[2:0]	word28 = fifo[28];
wire	[2:0]	word29 = fifo[29];
wire	[2:0]	word30 = fifo[30];
wire	[2:0]	word31 = fifo[31];

wire	[2:0]	word32 = fifo[32];
wire	[2:0]	word33 = fifo[33];
wire	[2:0]	word34 = fifo[34];
wire	[2:0]	word35 = fifo[35];
wire	[2:0]	word36 = fifo[36];
wire	[2:0]	word37 = fifo[37];
wire	[2:0]	word38 = fifo[38];
wire	[2:0]	word39 = fifo[39];

wire	[2:0]	word40 = fifo[40];
wire	[2:0]	word41 = fifo[41];
wire	[2:0]	word42 = fifo[42];
wire	[2:0]	word43 = fifo[43];
wire	[2:0]	word44 = fifo[44];
wire	[2:0]	word45 = fifo[45];
wire	[2:0]	word46 = fifo[46];
wire	[2:0]	word47 = fifo[47];

wire	[2:0]	word48 = fifo[48];
wire	[2:0]	word49 = fifo[49];
wire	[2:0]	word50 = fifo[50];
wire	[2:0]	word51 = fifo[51];
wire	[2:0]	word52 = fifo[52];
wire	[2:0]	word53 = fifo[53];
wire	[2:0]	word54 = fifo[54];
wire	[2:0]	word55 = fifo[55];

wire	[2:0]	word56 = fifo[56];
wire	[2:0]	word57 = fifo[57];
wire	[2:0]	word58 = fifo[58];
wire	[2:0]	word59 = fifo[59];
wire	[2:0]	word60 = fifo[60];
wire	[2:0]	word61 = fifo[61];
wire	[2:0]	word62 = fifo[62];
wire	[2:0]	word63 = fifo[63];

wire	[2:0]	word64 = fifo[64];
wire	[2:0]	word65 = fifo[65];
wire	[2:0]	word66 = fifo[66];
wire	[2:0]	word67 = fifo[67];
wire	[2:0]	word68 = fifo[68];
wire	[2:0]	word69 = fifo[69];
wire	[2:0]	word70 = fifo[70];
wire	[2:0]	word71 = fifo[71];

wire	[2:0]	word72 = fifo[72];
wire	[2:0]	word73 = fifo[73];
wire	[2:0]	word74 = fifo[74];
wire	[2:0]	word75 = fifo[75];
wire	[2:0]	word76 = fifo[76];
wire	[2:0]	word77 = fifo[77];
wire	[2:0]	word78 = fifo[78];
wire	[2:0]	word79 = fifo[79];

wire	[2:0]	word80 = fifo[80];
wire	[2:0]	word81 = fifo[81];
wire	[2:0]	word82 = fifo[82];
wire	[2:0]	word83 = fifo[83];
wire	[2:0]	word84 = fifo[84];
wire	[2:0]	word85 = fifo[85];
wire	[2:0]	word86 = fifo[86];
wire	[2:0]	word87 = fifo[87];

wire	[2:0]	word88 = fifo[88];
wire	[2:0]	word89 = fifo[89];
wire	[2:0]	word90 = fifo[90];
wire	[2:0]	word91 = fifo[91];
wire	[2:0]	word92 = fifo[92];
wire	[2:0]	word93 = fifo[93];
wire	[2:0]	word94 = fifo[94];
wire	[2:0]	word95 = fifo[95];

wire	[2:0]	word96 = fifo[96];
wire	[2:0]	word97 = fifo[97];
wire	[2:0]	word98 = fifo[98];
wire	[2:0]	word99 = fifo[99];
wire	[2:0]	word100 = fifo[100];
wire	[2:0]	word101 = fifo[101];
wire	[2:0]	word102 = fifo[102];
wire	[2:0]	word103 = fifo[103];

wire	[2:0]	word104 = fifo[104];
wire	[2:0]	word105 = fifo[105];
wire	[2:0]	word106 = fifo[106];
wire	[2:0]	word107 = fifo[107];
wire	[2:0]	word108 = fifo[108];
wire	[2:0]	word109 = fifo[109];
wire	[2:0]	word110 = fifo[110];
wire	[2:0]	word111 = fifo[111];

wire	[2:0]	word112 = fifo[112];
wire	[2:0]	word113 = fifo[113];
wire	[2:0]	word114 = fifo[114];
wire	[2:0]	word115 = fifo[115];
wire	[2:0]	word116 = fifo[116];
wire	[2:0]	word117 = fifo[117];
wire	[2:0]	word118 = fifo[118];
wire	[2:0]	word119 = fifo[119];

wire	[2:0]	word120 = fifo[120];
wire	[2:0]	word121 = fifo[121];
wire	[2:0]	word122 = fifo[122];
wire	[2:0]	word123 = fifo[123];
wire	[2:0]	word124 = fifo[124];
wire	[2:0]	word125 = fifo[125];
wire	[2:0]	word126 = fifo[126];
wire	[2:0]	word127 = fifo[127];

wire	[2:0]	word128 = fifo[128];
wire	[2:0]	word129 = fifo[129];
wire	[2:0]	word130 = fifo[130];
wire	[2:0]	word131 = fifo[131];
wire	[2:0]	word132 = fifo[132];
wire	[2:0]	word133 = fifo[133];
wire	[2:0]	word134 = fifo[134];
wire	[2:0]	word135 = fifo[135];

wire	[2:0]	word136 = fifo[136];
wire	[2:0]	word137 = fifo[137];
wire	[2:0]	word138 = fifo[138];
wire	[2:0]	word139 = fifo[139];
wire	[2:0]	word140 = fifo[140];
wire	[2:0]	word141 = fifo[141];
wire	[2:0]	word142 = fifo[142];
wire	[2:0]	word143 = fifo[143];

wire	[2:0]	word144 = fifo[144];
wire	[2:0]	word145 = fifo[145];
wire	[2:0]	word146 = fifo[146];
wire	[2:0]	word147 = fifo[147];
wire	[2:0]	word148 = fifo[148];
wire	[2:0]	word149 = fifo[149];
wire	[2:0]	word150 = fifo[150];
wire	[2:0]	word151 = fifo[151];

wire	[2:0]	word152 = fifo[152];
wire	[2:0]	word153 = fifo[153];
wire	[2:0]	word154 = fifo[154];
wire	[2:0]	word155 = fifo[155];
wire	[2:0]	word156 = fifo[156];
wire	[2:0]	word157 = fifo[157];
wire	[2:0]	word158 = fifo[158];
wire	[2:0]	word159 = fifo[159];

wire	[2:0]	word160 = fifo[160];
wire	[2:0]	word161 = fifo[161];
wire	[2:0]	word162 = fifo[162];
wire	[2:0]	word163 = fifo[163];
wire	[2:0]	word164 = fifo[164];
wire	[2:0]	word165 = fifo[165];
wire	[2:0]	word166 = fifo[166];
wire	[2:0]	word167 = fifo[167];

wire	[2:0]	word168 = fifo[168];
wire	[2:0]	word169 = fifo[169];
wire	[2:0]	word170 = fifo[170];
wire	[2:0]	word171 = fifo[171];
wire	[2:0]	word172 = fifo[172];
wire	[2:0]	word173 = fifo[173];
wire	[2:0]	word174 = fifo[174];
wire	[2:0]	word175 = fifo[175];

wire	[2:0]	word176 = fifo[176];
wire	[2:0]	word177 = fifo[177];
wire	[2:0]	word178 = fifo[178];
wire	[2:0]	word179 = fifo[179];
wire	[2:0]	word180 = fifo[180];
wire	[2:0]	word181 = fifo[181];
wire	[2:0]	word182 = fifo[182];
wire	[2:0]	word183 = fifo[183];

wire	[2:0]	word184 = fifo[184];
wire	[2:0]	word185 = fifo[185];
wire	[2:0]	word186 = fifo[186];
wire	[2:0]	word187 = fifo[187];
wire	[2:0]	word188 = fifo[188];
wire	[2:0]	word189 = fifo[189];
wire	[2:0]	word190 = fifo[190];
wire	[2:0]	word191 = fifo[191];

wire	[2:0]	word192 = fifo[192];
wire	[2:0]	word193 = fifo[193];
wire	[2:0]	word194 = fifo[194];
wire	[2:0]	word195 = fifo[195];
wire	[2:0]	word196 = fifo[196];
wire	[2:0]	word197 = fifo[197];
wire	[2:0]	word198 = fifo[198];
wire	[2:0]	word199 = fifo[199];

wire	[2:0]	word200 = fifo[200];
wire	[2:0]	word201 = fifo[201];
wire	[2:0]	word202 = fifo[202];
wire	[2:0]	word203 = fifo[203];
wire	[2:0]	word204 = fifo[204];
wire	[2:0]	word205 = fifo[205];
wire	[2:0]	word206 = fifo[206];
wire	[2:0]	word207 = fifo[207];

wire	[2:0]	word208 = fifo[208];
wire	[2:0]	word209 = fifo[209];
wire	[2:0]	word210 = fifo[210];
wire	[2:0]	word211 = fifo[211];
wire	[2:0]	word212 = fifo[212];
wire	[2:0]	word213 = fifo[213];
wire	[2:0]	word214 = fifo[214];
wire	[2:0]	word215 = fifo[215];

wire	[2:0]	word216 = fifo[216];
wire	[2:0]	word217 = fifo[217];
wire	[2:0]	word218 = fifo[218];
wire	[2:0]	word219 = fifo[219];
wire	[2:0]	word220 = fifo[220];
wire	[2:0]	word221 = fifo[221];
wire	[2:0]	word222 = fifo[222];
wire	[2:0]	word223 = fifo[223];

wire	[2:0]	word224 = fifo[224];
wire	[2:0]	word225 = fifo[225];
wire	[2:0]	word226 = fifo[226];
wire	[2:0]	word227 = fifo[227];
wire	[2:0]	word228 = fifo[228];
wire	[2:0]	word229 = fifo[229];
wire	[2:0]	word230 = fifo[230];
wire	[2:0]	word231 = fifo[231];

wire	[2:0]	word232 = fifo[232];
wire	[2:0]	word233 = fifo[233];
wire	[2:0]	word234 = fifo[234];
wire	[2:0]	word235 = fifo[235];
wire	[2:0]	word236 = fifo[236];
wire	[2:0]	word237 = fifo[237];
wire	[2:0]	word238 = fifo[238];
wire	[2:0]	word239 = fifo[239];

wire	[2:0]	word240 = fifo[240];
wire	[2:0]	word241 = fifo[241];
wire	[2:0]	word242 = fifo[242];
wire	[2:0]	word243 = fifo[243];
wire	[2:0]	word244 = fifo[244];
wire	[2:0]	word245 = fifo[245];
wire	[2:0]	word246 = fifo[246];
wire	[2:0]	word247 = fifo[247];

wire	[2:0]	word248 = fifo[248];
wire	[2:0]	word249 = fifo[249];
wire	[2:0]	word250 = fifo[250];
wire	[2:0]	word251 = fifo[251];
wire	[2:0]	word252 = fifo[252];
wire	[2:0]	word253 = fifo[253];
wire	[2:0]	word254 = fifo[254];
wire	[2:0]	word255 = fifo[255];




// a 1 is returned if any of the error bits in the fifo is 1
assign	error_bit = 	|(word0[2:0]  | word1[2:0]  | word2[2:0]  | word3[2:0]  |
            		      word4[2:0]  | word5[2:0]  | word6[2:0]  | word7[2:0]  |
            		      word8[2:0]  | word9[2:0]  | word10[2:0] | word11[2:0] |
            		      word12[2:0] | word13[2:0] | word14[2:0] | word15[2:0] | 
						  word16[2:0] | word17[2:0] | word18[2:0] | word19[2:0] |
						  word20[2:0] | word21[2:0] | word22[2:0] | word23[2:0] |
						  word24[2:0] | word25[2:0] | word26[2:0] | word27[2:0] |
						  word28[2:0] | word29[2:0] | word30[2:0] | word31[2:0] |
						  word32[2:0] | word33[2:0] | word34[2:0] | word35[2:0] |
						  word36[2:0] | word37[2:0] | word38[2:0] | word39[2:0] |
						  word40[2:0] | word41[2:0] | word42[2:0] | word43[2:0] |
						  word44[2:0] | word45[2:0] | word46[2:0] | word47[2:0] |
						  word48[2:0] | word49[2:0] | word50[2:0] | word51[2:0] |
						  word52[2:0] | word53[2:0] | word54[2:0] | word55[2:0] |
						  word56[2:0] | word57[2:0] | word58[2:0] | word59[2:0] |
						  word60[2:0] | word61[2:0] | word62[2:0] | word63[2:0] |
						  word64[2:0] | word65[2:0] | word66[2:0] | word67[2:0] |
						  word68[2:0] | word69[2:0] | word70[2:0] | word71[2:0] |
						  word72[2:0] | word73[2:0] | word74[2:0] | word75[2:0] |
						  word76[2:0] | word77[2:0] | word78[2:0] | word79[2:0] |
						  word80[2:0] | word81[2:0] | word82[2:0] | word83[2:0] |
						  word84[2:0] | word85[2:0] | word86[2:0] | word87[2:0] |
						  word88[2:0] | word89[2:0] | word90[2:0] | word91[2:0] |
						  word92[2:0] | word93[2:0] | word94[2:0] | word95[2:0] |
						  word96[2:0] | word97[2:0] | word98[2:0] | word99[2:0] |
						  word100[2:0] | word101[2:0] | word102[2:0] | word103[2:0] |
						  word104[2:0] | word105[2:0] | word106[2:0] | word107[2:0] |
						  word108[2:0] | word109[2:0] | word110[2:0] | word111[2:0] |
						  word112[2:0] | word113[2:0] | word114[2:0] | word115[2:0] |
						  word116[2:0] | word117[2:0] | word118[2:0] | word119[2:0] |
						  word120[2:0] | word121[2:0] | word122[2:0] | word123[2:0] |
						  word124[2:0] | word125[2:0] | word126[2:0] | word127[2:0] |
						  word128[2:0] | word129[2:0] | word130[2:0] | word131[2:0] |
						  word132[2:0] | word133[2:0] | word134[2:0] | word135[2:0] |
						  word136[2:0] | word137[2:0] | word138[2:0] | word139[2:0] |
						  word140[2:0] | word141[2:0] | word142[2:0] | word143[2:0] |
						  word144[2:0] | word145[2:0] | word146[2:0] | word147[2:0] |
						  word148[2:0] | word149[2:0] | word150[2:0] | word151[2:0] |
						  word152[2:0] | word153[2:0] | word154[2:0] | word155[2:0] |
						  word156[2:0] | word157[2:0] | word158[2:0] | word159[2:0] |
						  word160[2:0] | word161[2:0] | word162[2:0] | word163[2:0] |
						  word164[2:0] | word165[2:0] | word166[2:0] | word167[2:0] |
						  word168[2:0] | word169[2:0] | word170[2:0] | word171[2:0] |
						  word172[2:0] | word173[2:0] | word174[2:0] | word175[2:0] |
						  word176[2:0] | word177[2:0] | word178[2:0] | word179[2:0] |
						  word180[2:0] | word181[2:0] | word182[2:0] | word183[2:0] |
						  word184[2:0] | word185[2:0] | word186[2:0] | word187[2:0] |
						  word188[2:0] | word189[2:0] | word190[2:0] | word191[2:0] |
						  word192[2:0] | word193[2:0] | word194[2:0] | word195[2:0] |
						  word196[2:0] | word197[2:0] | word198[2:0] | word199[2:0] |
						  word200[2:0] | word201[2:0] | word202[2:0] | word203[2:0] |
						  word204[2:0] | word205[2:0] | word206[2:0] | word207[2:0] |
						  word208[2:0] | word209[2:0] | word210[2:0] | word211[2:0] |
						  word212[2:0] | word213[2:0] | word214[2:0] | word215[2:0] |
						  word216[2:0] | word217[2:0] | word218[2:0] | word219[2:0] |
						  word220[2:0] | word221[2:0] | word222[2:0] | word223[2:0] |
						  word224[2:0] | word225[2:0] | word226[2:0] | word227[2:0] |
						  word228[2:0] | word229[2:0] | word230[2:0] | word231[2:0] |
						  word232[2:0] | word233[2:0] | word234[2:0] | word235[2:0] |
						  word236[2:0] | word237[2:0] | word238[2:0] | word239[2:0] |
						  word240[2:0] | word241[2:0] | word242[2:0] | word243[2:0] |
						  word244[2:0] | word245[2:0] | word246[2:0] | word247[2:0] |
						  word248[2:0] | word249[2:0] | word250[2:0] | word251[2:0] |
						  word252[2:0] | word253[2:0] | word254[2:0] | word255[2:0]); 
endmodule
